/**
 * Created by Administrator on 2018/1/22.
 */
// 发布商品
function uploadImgs(upload) {
    //普通图片上传
    upload.render({
        elem: '#up1'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-img'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up1').siblings('img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up2'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-img'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up2').siblings('img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up3'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-img'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up3').siblings('img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up4'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-img'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up4').siblings('img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up5'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-img'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up5').siblings('img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });

    upload.render({
        elem: '#gpic'
        ,url: ''    //服务端上传接口
        ,auto: false
        ,bindAction: '#post-info'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#preview').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var uploadtext = $('#uploadtext');
            uploadtext.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            uploadtext.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });
}
// 店铺设置
function uploadLogo(upload) {
    upload.render({
        elem: '#uplogo'
        ,url: ''    //服务端上传接口
        ,auto: false
        ,bindAction: '#shoppost'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            console.log(obj)
            obj.preview(function(index, file, result){
                $('.logo-wrap img').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
        }
        ,error: function(){
        }
    });
    upload.render({
        elem: '#upbanner'
        ,url: ''    //服务端上传接口
        ,auto: false
        ,bindAction: '#shoppost'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            console.log(obj)
            obj.preview(function(index, file, result){
                $('.banner-wrap img').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
        }
        ,error: function(){
        }
    });
    //幻灯片上传
    upload.render({
        elem: '#up1'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-slide'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up1').parents('.uw').find('.pic img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up2'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-slide'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up2').parents('.uw').find('.pic img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up3'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-slide'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up3').parents('.uw').find('.pic img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up4'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-slide'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up4').parents('.uw').find('.pic img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    upload.render({
        elem: '#up5'
        ,url: '' //服务端上传接口
        ,auto: false
        ,bindAction: '#post-slide'
        ,choose: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#up5').parents('.uw').find('.pic img').attr('src', result);
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
}